package com.simple.datax.dao.impl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.simple.base.dao.BaseDAO;
import com.simple.datax.dao.IDataxSendRawMsgDAO;
import com.simple.datax.vo.DataxSendRawMsgVO;
import com.simple.util.common.StringUtil;
import com.simple.util.object.PageInfoBean;

@Repository("dataxSendRawMsgDAO")
public class DataxSendRawMsgDAOImpl extends BaseDAO implements IDataxSendRawMsgDAO {

	@Override
	public DataxSendRawMsgVO findById(String fcRecvRawMsgId) {
		return (DataxSendRawMsgVO)super.get(DataxSendRawMsgVO.class, fcRecvRawMsgId);
	}

	@Override
	public void saveOrUpdate(DataxSendRawMsgVO dataxSendRawMsgVO) {
		super.saveOrUpdate(dataxSendRawMsgVO);
	}

	@Override
	public List<DataxSendRawMsgVO> findAll() {
		return super.query(DataxSendRawMsgVO.class);
	}
	
	@Override
	public void delete(DataxSendRawMsgVO dataxSendRawMsgVO) {
		super.delete(dataxSendRawMsgVO);	
	}

	@Override
	public void delete(String fcRecvRawMsgId) {	
		super.delete(DataxSendRawMsgVO.class, fcRecvRawMsgId);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<DataxSendRawMsgVO> findDataxSendRawMsgVOByPage(
			PageInfoBean pageInfoBean, String fcRecvRawMsgId,
			String fcMessageId, String fcSenderId, String fcReceiverId,
			String fromDate, String toDate) {
		final Map<String, Object> paramMap = new LinkedHashMap<String,Object>();
        final StringBuffer sb = new StringBuffer(300);
        
        sb.append( "select  d from DataxSendRawMsgVO d where 1>0 " );
        if(!StringUtil.isNull(fcRecvRawMsgId)){
            sb.append( " and d.fcRecvRawMsgId like :fcRecvRawMsgId" );
            paramMap.put("fcRecvRawMsgId","%"+fcRecvRawMsgId+"%");
        }
        if(!StringUtil.isNull(fcMessageId)){
            sb.append( " and d.fcMessageId like :fcMessageId" );
            paramMap.put("fcMessageId","%"+fcMessageId+"%");
        }
        if(!StringUtil.isNull(fcSenderId)){
            sb.append( " and d.fcSenderId like :fcSenderId" );
            paramMap.put("fcSenderId", "%"+fcSenderId+"%");
        }
        if(!StringUtil.isNull(fcReceiverId)){
            sb.append( " and d.fcReceiverId like :fcReceiverId" );
            paramMap.put("fcReceiverId","%"+fcReceiverId+"%");
        }
        if(!StringUtil.isNull(fromDate)){
            sb.append( " and to_char(d.fdBackUpTime,'yyyy-MM-dd HH24:mi:ss')>=:fromDate" );
            paramMap.put("fromDate", fromDate);
        }
        if(!StringUtil.isNull(toDate)){
            sb.append( " and to_char(d.fdBackUpTime,'yyyy-MM-dd HH24:mi:ss')<=:toDate");
            paramMap.put("toDate", toDate);
        }
        sb.append( " order by d.fcRecvRawMsgId desc" );
        return (List<DataxSendRawMsgVO>) super.queryListByPage("d.fcRecvRawMsgId", sb.toString(), paramMap, pageInfoBean);
	}

}
